<!--
 * @Author: wuyuxin
 * @Date: 2023-10-16 10:19:19
 * @LastEditors: wuyuxin
 * @LastEditTime: 2023-10-16 11:16:01
 * @Description: 
-->
<template>
  <div class="city top-page">
    <div class="top">
      <!-- 1.搜索框 -->
      <van-search 
        v-model="searchValue" 
        placeholder="城市/区域/位置"
        shape="round"
        show-action
        @cancel="cancelClick"
      />

      <van-tabs v-model:active="activeName" color="#ff9854" line-height="3">
        <template v-for="(item, key, index) in allCities">
          <van-tab :title="item.title" :name="key"></van-tab>
        </template>
      </van-tabs>
    </div>
    <div class="content">
      <template v-for="(item, key, index) in allCities">
        <CityGroup v-show="key === activeName" :groupData="item"></CityGroup>
      </template>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router';
import useCityStore from '@/stores/modules/city.js'
import { storeToRefs } from 'pinia';

import CityGroup from './components/CityGroup.vue'

const router = useRouter();

const searchValue = ref();

const cancelClick = () => {
  router.back();
}

const cityStore = useCityStore();
const { allCities } = storeToRefs(cityStore)
cityStore.fetchAllCitiesData();

const activeName = ref();

</script>

<style lang="less" scoped>
.city {
  .top {
    position: relative;

    z-index: 9;
  }

  .content {
    height: calc(100vh - 98px);
    overflow-y: auto;
  }
}

</style>